import pymysql

while True:
    user = input("用户名:")
    if user.upper() == "Q":
        break
    pwd = input("密码:")
    mobile = input("手机号:")

    # 1.连接MySQL
    conn = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="123456", charset="utf8mb4", db="zzm")
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)

    # 2.发送指令(*** 千万不要用字符串格式化去做sql拼接，安全隐患sql注入***)
    sql = "insert into admin(username,password,mobile) values(%s,%s,%s)"
    cursor.execute(sql, [user, pwd, mobile])
    # 第二种写法
    # sql = "insert into admin(username,password,moblie) values(%(n1)s,%(n2)s,%(n3)s)"
    # cursor.execute(sql, {"n1": "李四", "n2": "qwe123", "n3": "12345678901"})
    conn.commit()
    # 3.关闭
    cursor.close()
    conn.close()
# 在进行新增，删除，修改时，一定要记得commit，不然数据库没有数据
# cursor.execute("...")
# conn.commit()
